import config from './config'
export default (url, data = {}, method = 'GET') => {
  return new Promise((resolve, reject) =>{
    wx.request({
      url: config.host + url, //本机调试
      //url: config.mobilehost + url, //真机调试
      data,
      method,
      header: {
        cookie: wx.getStorageSync('cookies') ? wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U') !== -1) : ''
      },
      success: (res) => {
        if (data.isLogin) {
          // 将用户的cookie存至本地
          wx.setStorage({
            key: 'cookies',
            data: res.cookies,
          });
        }
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      }
    })
  })
}